package io.renren.api.menu;

import cn.hutool.core.util.StrUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("/custom")
@Slf4j
public class MenuIndexController {

    @RequestMapping("/*.html")
    public String getPage(Model model, HttpServletRequest request) {

        String home = StrUtil.subBefore(StrUtil.subAfter(request.getRequestURI(),"/",true),".",true);
        //获取所有参数，并且传递到页面中
        Enumeration paramNames = request.getParameterNames();
        while (paramNames.hasMoreElements()) {
            String paramName = (String) paramNames.nextElement();

            String[] paramValues = request.getParameterValues(paramName);
            if (paramValues.length == 1) {
                String paramValue = paramValues[0];
                if (paramValue.length() != 0) {
                    model.addAttribute(paramName, paramValue);
                }
            }
        }

        return "menu/" + home;
    }
}
